package jcu.sal.agent.netty;

import static org.jboss.netty.channel.Channels.pipeline;
import jcu.sal.agent.NettyAgentImpl;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;

/**
 * @author Marc Hammerton
 *
 */
public class NettyAgentPipelineFactory implements ChannelPipelineFactory {

	private NettyAgentImpl agent;
	
	public NettyAgentPipelineFactory(NettyAgentImpl agent) {
		this.agent = agent;
	}
	
	/* (non-Javadoc)
	 * @see org.jboss.netty.channel.ChannelPipelineFactory#getPipeline()
	 */
	@Override
	public ChannelPipeline getPipeline() throws Exception {
		
		ChannelPipeline pipeline = pipeline();
		
		// Add codecs
		pipeline.addLast("decoder", new NettyAgentMessageDecoder());
		pipeline.addLast("encoder", new NettyAgentMessageEncoder());
		
		pipeline.addLast("handler", new NettyAgentHandler(agent));
		
		return pipeline;
	}

}
